<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of report
 *
 * @author Константин Охотник
 */

class SomeOrder extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->issetSession('SomeOrder');
        $this->load->model('SomeOrderModel');
    }
    
    public function index($id=false,$printorder=false)
    {
        if($id==false)
        {
            redirect('/orders/', 'refresh');
        }
        $order_data =   $this->SomeOrderModel->getOrderData($id);
        $categories =   $this->SomeOrderModel->getCategory();
        $fabricator =   $this->SomeOrderModel->getFabricator();
        $product    =   $this->SomeOrderModel->getProduct();
        $site       =   $this->SomeOrderModel->getSite();
        $this->crud
        ->assign('order_data', $order_data)
        ->assign('categories', $categories)
        ->assign('fabricator', $fabricator)
        ->assign('product', $product)
        ->assign('site', $site);
        //var_dump($order_data);die;
        if($printorder == false)
        {
            $this->crud->display('someorder.tpl');
        }
        else
        {
            $this->crud->display('module/printorder.tpl');
        }
    }
    
    public function insertdata()
    {
        $data = $this->input->post();
        $id = $data['id'];
        unset($data['id']);
        die($this->SomeOrderModel->update_post('tb_order', 'id', $id, $data));
    }
    
    public function newbookexcel($id)
    {
        echo $this->SomeOrderModel->orderToExcel($id);
    }
}